﻿<Window x:Class="Glissando.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Glissando"
    xmlns:h="clr-namespace:HelixToolkit;assembly=HelixToolkit"
    Title="{Binding Title, StringFormat='Glissando - {0}'}" 
    Height="450" Width="800" 
    Icon="/Glissando;component/Resources/piano.png"
    Keyboard.KeyDown="Window_KeyDown"
    Keyboard.KeyUp="Window_KeyUp"
    AllowDrop="true" Drop="Window_Drop"
        Background="Black"
    x:Name="ThisWindow"
>
    <Window.Resources>
    </Window.Resources>
    <DockPanel Background="Transparent">
        <Menu Name="MainMenu" DockPanel.Dock="Top">
            <MenuItem Header="_File" VerticalAlignment="Center">
                <MenuItem Header="_Open MIDI file..." InputGestureText="Ctrl-O" Command="Open"/>
                <Separator/>
                <MenuItem Command="local:MainWindow.Settings"/>
                <Separator/>
                <MenuItem Command="local:MainWindow.ExitApplication"/>
            </MenuItem>
            <MenuItem Header="_Test">
                <MenuItem IsChecked="{Binding IsPitchTestRunning}" Command="local:MainWindow.StartPitchTest"/>
            </MenuItem>
            <MenuItem Header="_Jam">
                <MenuItem Header="_Enter room..." Command="{Binding JamEnterCommand}"/>
                <MenuItem Header="_Leave room" Command="{Binding JamLeaveCommand}"/>
            </MenuItem>
            <MenuItem Header="_View" VerticalAlignment="Center">
                <MenuItem Header="Reset view"/>
                <MenuItem IsChecked="{Binding ColoredKeys}" Command="local:MainWindow.ColoredKeys"/>
                <MenuItem IsChecked="{Binding IsFullScreen}" Command="local:MainWindow.ViewFullScreen"/>
<!--                <Separator/>
                <MenuItem IsChecked="{Binding Stereo}" Command="local:MainWindow.ViewStereo"/>
                <Separator/>
                <MenuItem Command="local:MainWindow.ViewExport"/>-->
            </MenuItem>
            <MenuItem Header="_Channels">
                <MenuItem IsChecked="{Binding Channel01}" Header="Channel 1" IsCheckable="True"/>
                <MenuItem IsChecked="{Binding Channel02}" Header="Channel 2" IsCheckable="True"/>
            </MenuItem>
            <MenuItem Name="InstrumentsMenu" Header="_Instrument" VerticalAlignment="Center">
                <MenuItem Header="Acoustic grand piano" Tag="0" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Bright acoustic piano" Tag="1" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Electric grand piano" Tag="2" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Honky-tonk piano" Tag="3" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Electric piano 1" Tag="4" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Electric piano 2" Tag="5" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Drawbar organ" Tag="16" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Percussive organ" Tag="17" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Rock organ" Tag="18" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Church organ" Tag="19" Click="ChangeInstrument_Click"/>
                <MenuItem Header="Reed organ" Tag="20" Click="ChangeInstrument_Click"/>
            </MenuItem>
            <MenuItem Header="_Help" VerticalAlignment="Center">
                <MenuItem Header="Web site" Click="HelpWeb_Click"/>
                <MenuItem Header="Discussion forum" Click="HelpForum_Click"/>
                <MenuItem Header="E-mail feedback" Click="Feedback_Click"/>
                <Separator/>
                <MenuItem Name="HelpAboutItem" Header="_About..." Command="local:MainWindow.HelpAbout"/>
            </MenuItem>

        </Menu>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"/>
                <RowDefinition/>
                <RowDefinition Height="120"/>
            </Grid.RowDefinitions>
            <Grid Name="MainGrid" Grid.Row="0" Grid.RowSpan="3">
                <!-- 3D VIEWPORT -->
                <h:HelixView3D Name="View" IsHeadLightEnabled="False" ShowViewCube="False" ShowCoordinateSystem="False">
                    <local:PianoModel3D x:Name="piano" ColoredKeys="{Binding ColoredKeys}"/>

                    <!-- LIGHTS -->
                    <ModelVisual3D >
                        <ModelVisual3D.Content>
                            <Model3DGroup x:Name="Lights">

                                <!--<AmbientLight Color="#404040"/>
                                <DirectionalLight Color="#808080" Direction="-2,-3,-1" />
                                <PointLight Color="#808080" Position="-700 0 700"/>
                                <PointLight Color="#808080" Position="700 0 700"/>
-->
                                <!--
                                <AmbientLight Color="#101010"/>
                                <PointLight Color="#808080" Position="0 0 700"/>
                                <PointLight Color="#404040" Position="-700 -700 700"/>
                                <PointLight Color="#404040" Position="700 -700 700"/>
                                <PointLight Color="#202020" Position="0 700 700"/>
                                -->

                                <AmbientLight Color="#101010"/>
                                <SpotLight Color="#606060" Position="0 400 2000" Direction="0,0,-1"/>
                                <SpotLight Color="#404040" Position="2000 -400 0" Direction="-20,4,0"/>
                                <SpotLight Color="#404040" Position="-2000 -400 0" Direction="20,4,0"/>
                                <DirectionalLight Color="#a0a0a0" Direction="-2,-3,-1" />
                                <DirectionalLight Color="#a0a0a0" Direction="2,-3,-1" />

                            </Model3DGroup>
                        </ModelVisual3D.Content>
                    </ModelVisual3D>
                </h:HelixView3D>
            </Grid>
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" 
                        Visibility="{Binding IsLoading, Converter={local:BoolToVisibilityConverter}}">
                <ProgressBar DockPanel.Dock="Top" Name="LoadingProgress" Value="{Binding LoadingProgress}" Width="200" Height="14"  Margin="4"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" 
                        Visibility="{Binding IsMidiFileLoaded, Converter={local:BoolToVisibilityConverter}}">
                <StackPanel.Resources>
                    <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                        <Setter Property="Width" Value="50"/>
                        <Setter Property="Height" Value="24"/>
                        <Setter Property="Margin" Value="4"/>
                        <Setter Property="Padding" Value="2"/>
                    </Style>
                </StackPanel.Resources>
                <Button Content="Play" Command="local:MainWindow.Start"/>
                <Button Content="Pause" Command="local:MainWindow.Pause"/>
                <Button Content="Stop" Command="local:MainWindow.Stop"/>
                <Button Content="Slower" Command="local:MainWindow.ReduceSpeed" />
                <Button Content="Normal" Command="local:MainWindow.NormalSpeed"/>
                <Slider Name="SliderPosition" 
                        Width="200" Margin="4"
                        Value="{Binding SequencePosition, Mode=TwoWay}" 
                        Maximum="{Binding SequenceLength}" 
                        VerticalAlignment="Center"
                        IsSelectionRangeEnabled="True"
                        SelectionStart="{Binding LoopStartPosition}"
                        SelectionEnd="{Binding LoopEndPosition}"
                        />
                <Label Content="{Binding Time}" VerticalAlignment="Center" ToolTip="Time" Foreground="Gray" Padding="10 0 20 0" Width="100"/>
                <Button Content="[" Width="30" ToolTip="Set loop start point" Command="local:MainWindow.SetLoopStart"/>
                <Button Content="]" Width="30" ToolTip="Set loop end point" Command="local:MainWindow.SetLoopEnd"/>
                <CheckBox Content="Loop" IsChecked="{Binding IsLooping}" VerticalAlignment="Center"/>
            </StackPanel>

            <!--
            <local:StaffControl Grid.Row="1" Height="80" VerticalAlignment="Bottom" Background="#c0ffffff" Foreground="Black"/>
            -->

            <!-- Pitch test: Showing results -->
            <Label Grid.Row="2" 
                   Content="{Binding PlayTitle}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="16"
                   Visibility="{Binding IsFullScreen, Converter={local:BoolToVisibilityConverter}}"
                   ToolTip="Playing" Foreground="#80ffffff" 
                   FontFamily="TradeGothic, Arial" 
                   FontSize="24" FontWeight="Bold">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>


            <StackPanel Grid.Row="0" Grid.RowSpan="3" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="16">
                <ItemsControl ItemsSource="{Binding JamBuddies}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <Label Content="{Binding}" FontSize="12" FontWeight="Bold"
                                       Foreground="#80ffffff" VerticalAlignment="Center">
                                    <Label.Effect>
                                        <DropShadowEffect/>
                                    </Label.Effect>
                                </Label>
                                <Rectangle Width="20" Height="20" RadiusX="3" RadiusY="3" 
                                           Fill="{Binding Color, Converter={local:ColorToBrushConverter}}" 
                                          Margin="4"/>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <Label  
                   Content="{Binding JamStatus}" HorizontalAlignment="Right" Margin="16"
                   ToolTip="Jam status" Foreground="#80ffffff" 
                   FontFamily="TradeGothic, Arial" 
                   FontSize="24" FontWeight="Bold">
                    <Label.Effect>
                        <DropShadowEffect/>
                    </Label.Effect>
                </Label>
            </StackPanel>

            <!-- Pitch test: Showing results -->
            <Label Grid.Row="2" 
                   Content="{Binding TestResult}" VerticalAlignment="Center" HorizontalAlignment="Center" 
                   ToolTip="Pitch test result (Correct : Incorrect / Count)" Foreground="#a0a0a0a0" FontSize="100"
                   FontFamily="Arial" FontWeight="Bold">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>

            <!-- Pitch test: Showing the correct note name-->
            <Label Grid.Row="1" 
                   Content="{Binding NoteName}" VerticalAlignment="Bottom" HorizontalAlignment="Center" 
                   Foreground="White" FontSize="140"
                   FontFamily="Arial" FontWeight="Bold">
                <Label.Effect>
                    <DropShadowEffect/>
                </Label.Effect>
            </Label>

        </Grid>
    </DockPanel>
</Window>
